package com.itheima.stock.mapper;

import com.itheima.stock.common.domian.UserAddDomain;
import com.itheima.stock.common.domian.UserAndRoles;
import com.itheima.stock.common.domian.UserDomin;
import com.itheima.stock.common.domian.UserPageDomain;
import com.itheima.stock.pojo.SysPermission;
import com.itheima.stock.pojo.SysRole;
import com.itheima.stock.pojo.SysUser;
import com.itheima.stock.vo.req.UserMenus;
import com.itheima.stock.vo.resp.LoginRespVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author hyn
* @description 针对表【sys_user(用户表)】的数据库操作Mapper
* @createDate 2022-05-30 01:02:49
* @Entity com.itheima.stock.pojo.SysUser
*/
@Repository
public interface SysUserMapper {

    /**
     * 登录
     *
     * @username   用户名
     * @return
     */

    SysUser findByUsernamePassword(@Param("username") String username);

    int deleteByPrimaryKey(Long id);

    int insert(SysUser record);

    int insertSelective(SysUser record);

    SysUser selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(SysUser record);

    int updateByPrimaryKey(SysUser record);

    //查询用户权限信息
    List<SysPermission> selectAllUser(@Param("id") String id);

    List<UserMenus> selectTwoDic(@Param("pid") String pid);

    List<UserDomin> queryPageUserinfo(UserPageDomain userPageDomain);

    Boolean addUserData(SysUser sysUser);

    List<SysRole> queryAllUserRoles(@Param("uid") String userId);

    List<String> selectRoleByUserId(@Param("uid") String userId);

    boolean updateAllUsers(UserAddDomain sysUser);


    @Delete("delete from sys_user_role where user_id=#{uid}")
    boolean deleteByPrimaryKeyAllUserRoles(@Param("uid") String id);

    @Insert("INSERT INTO sys_user_role VALUES(#{urid},#{uid},#{rid},#{creteTime})")
    boolean insertUserAndRoles(@Param("uid") String userId, @Param("rid") String roleIds, @Param("creteTime") Date date,@Param("urid") String id);

    @Select("SELECT ID, USERNAME, PHONE, REAL_NAME, NICK_NAME, EMAIL, STATUS, SEX FROM sys_user WHERE id")
    SysUser getUserById(@Param("uid") Long id);

    @Update("update sys_user set status =#{status} where id=#{id}")
    boolean upDateUserStatus(UserAddDomain userAddDomain);
}
